import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/pages/home'
//  插件方式注册
Vue.use(VueRouter)

// 导出函数
export const createRouter = ()=>{
    const router = new VueRouter({
        mode: 'history', // 兼容前后端
        routes: [
            {
                path: '/',
                name: 'home',
                component: Home
            },
            {
                path: '/about',
                name: 'about',
                component: ()=> import('@/pages/about') //异步加载
            },
            {
                path: '/posts',
                name: 'posts',
                component: ()=> import('@/pages/Posts') //异步加载
            },
            {
                path: '*',
                name: 'err404',
                component: ()=>import('@/pages/404')
            }
        ]
    })
    // 导出路由
    return router
}